//
//  LRXHistroyHelpItemController.m
//  路人侠
//
//  Created by zhangxulong on 5/29/16.
//  Copyright © 2016 zhangxulong. All rights reserved.
//

#import "LRXHistroyHelpItemController.h"
#import "LRXHistroyHelpItemCell.h"
#import "LRXHistroyHelpItemModel.h"
#import "LRXHelpItemData.h"
#import <list>
static NSString * histroyItemID = @"histroyItemID";
@interface LRXHistroyHelpItemController ()<UITableViewDelegate,UITableViewDataSource>{
    list<LRXHistroyHelpItemModel *> items;
}
@property (nonatomic,weak) UITableView * tableView;

@end

@implementation LRXHistroyHelpItemController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor colorWithRed:243 green:243 blue:243];

    UITableView * tableView = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height) style:UITableViewStyleGrouped];
    tableView.delegate = self;
    tableView.dataSource = self;
    tableView.rowHeight = 360 * hScale;
    self.tableView = tableView;
    

    [self.view addSubview:tableView];
    
    HistroyLoadDataBlock loadDataBlock = ^(list<LRXHistroyHelpItemModel *> item){
        for (auto i = item.begin(); i != item.end(); i++){
            LRXHistroyHelpItemModel  * pp = *i;
            NSLog(@"%@",pp.profile_url);
        }
        items = item;
        if (item.size() <= 0) {
            [self.navigationController popViewControllerAnimated:YES];
            [LRXOfflineView showOfflineView:@"您没有帮带任务"];
        }
        else
            [self.tableView reloadData];
    };
    HistroyLoadFaildBlock loadFaildBlock = ^{};
    LRXHelpItemData * loadData = [[LRXHelpItemData alloc]initWithItemsWithMoreDataBlock:loadDataBlock moreDataFaildBlock:loadFaildBlock];
    [loadData loadMoreInfo:getHitoryUrl];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    LRXHistroyHelpItemCell *cell = [tableView dequeueReusableCellWithIdentifier:histroyItemID];
    if (!cell) {
        cell = [[LRXHistroyHelpItemCell alloc]init];
    }

    int p = 0;
    for (auto i = items.begin(); i != items.end(); i++,p++){
        LRXHistroyHelpItemModel  * pp = *i;
        if (p == indexPath.section)
        {
            [cell layoutSubviews:pp];
            break;
        }
    }
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    
    return cell;
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return items.size();
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return 1;
}
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    return 20 * hScale;
}
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
{
    return 20 * hScale;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
//    LRXHistroyHelpItemCell * cell = [tableView cellForRowAtIndexPath:indexPath];
    
}

@end
